home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16725 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: in1.uu.net!zdc!zippo!drn
  2. From: Clarence Chiang
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Creating an object via new with ONLY a pointer to the object
  5. Date: 11 Apr 1996 12:21:42 -0700
  6. Organization: Spider Island Software
  7. Sender: http@doc.zippo.com
  8. Message-ID: <4kjm46$pht@doc.zippo.com>
  9. References: <4kh07v$lno@crchh327.rich.bnr.ca> <4kifrt$lk1@ubszh.fh.zh.ubs.com>
  10. NNTP-Posting-Host: doorstop.spiderisland.com
  11.  
  12. In article <316CFD17.5656@ebc.ericsson.se>, Bjorn says...
  13. >
  14. >Ian Johnston (by ubsswop) wrote:
  15. >> 
  16. >> In article <4kh07v$lno@crchh327.rich.bnr.ca>, jobell@bnr.ca (Bret Bieghler) writes:
  17. >> |> An interesting problem I've come across... I was wondering if this
  18. >> |> is possible:
  19. >> |>
  20. >> |> I have a generic CommandObject which defines several pure virtual
  21. >> |> functions.  Derived from CommandObject are user commands, such
  22. >> |> as ExitCommand, StatusCommand, etc.
  23. >> |>
  24. >> |> To process a command (currently) I do the following:
  25. >> |>
  26. >> |>      CommandObject* basePtr;
  27. >> |>
  28. >> |>      if (command == "exit")
  29. >> |>      {
  30. >> |>              basePtr = new ExitCommand;
  31. >> |>              basePtr->implement();
  32. >> |>      }
  33. >> |>      else if (command == "status")
  34. >> |>      {
  35. >> |>              basePtr = new StatusCommand;
  36. >> |>              basePtr->implement();
  37. >> |>      }
  38. >> |>
  39. >> |> What I would LIKE to do is the the following:
  40. >> |>
  41. >> |>      CommandObject* basePtr =  new commandTable[command];
  42. >> |>
  43. >> |> where commandTable is an associative array as follows:
  44. >> |>
  45. >> |>      Key             Value
  46. >> |>      "exit"  ExitCommand*
  47. >> |>      "status"        StatusCommand*
  48.  
  49. Or you can use the Factory Method pattern. It, with many other very good design
  50. patterns, are discussed in the book "Design Patterns". I forget the names of the
  51. authors though.
  52.  
  53. Basically you will have a CommandFactory class which its sole purpose is so
  54. create different command objects.
  55.  
  56. Clarence Chiang
  57. Spider Island Software
  58.